package com.ruoyi.canteen.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.canteen.domain.CanteenMd;
import com.ruoyi.canteen.service.ICanteenMdService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 门店Controller
 * 
 * @author zhangw
 * @date 2021-09-08
 */
@RestController
@RequestMapping("/canteen/md")
public class CanteenMdController extends BaseController
{
    @Autowired
    private ICanteenMdService canteenMdService;

    /**
     * 查询门店列表
     */
    @PreAuthorize("@ss.hasPermi('canteen:md:list')")
    @GetMapping("/list")
    public TableDataInfo list(CanteenMd canteenMd)
    {
        startPage();
        List<CanteenMd> list = canteenMdService.selectCanteenMdList(canteenMd);
        return getDataTable(list);
    }

    /**
     * 导出门店列表
     */
    @PreAuthorize("@ss.hasPermi('canteen:md:export')")
    @Log(title = "门店", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CanteenMd canteenMd)
    {
        List<CanteenMd> list = canteenMdService.selectCanteenMdList(canteenMd);
        ExcelUtil<CanteenMd> util = new ExcelUtil<CanteenMd>(CanteenMd.class);
        return util.exportExcel(list, "门店数据");
    }

    /**
     * 获取门店详细信息
     */
    @PreAuthorize("@ss.hasPermi('canteen:md:query')")
    @GetMapping(value = "/{mdId}")
    public AjaxResult getInfo(@PathVariable("mdId") Long mdId)
    {
        return AjaxResult.success(canteenMdService.selectCanteenMdByMdId(mdId));
    }

    /**
     * 新增门店
     */
    @PreAuthorize("@ss.hasPermi('canteen:md:add')")
    @Log(title = "门店", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CanteenMd canteenMd)
    {
        return toAjax(canteenMdService.insertCanteenMd(canteenMd));
    }

    /**
     * 修改门店
     */
    @PreAuthorize("@ss.hasPermi('canteen:md:edit')")
    @Log(title = "门店", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CanteenMd canteenMd)
    {
        return toAjax(canteenMdService.updateCanteenMd(canteenMd));
    }

    /**
     * 删除门店
     */
    @PreAuthorize("@ss.hasPermi('canteen:md:remove')")
    @Log(title = "门店", businessType = BusinessType.DELETE)
	@DeleteMapping("/{mdIds}")
    public AjaxResult remove(@PathVariable Long[] mdIds)
    {
        return toAjax(canteenMdService.deleteCanteenMdByMdIds(mdIds));
    }
}
